<template>
  <div class="mapping-page">
    <!-- 头部盒子 -->
    <div class="header">
      <!-- 页面标题 -->
      <div class="title">
        <h4>颜色</h4>
      </div>
      <!-- 搜索框 -->
      <div class="right">
        <el-form :inline="true" style="display: inline-block" size="small">
          <el-form-item>
            <el-input placeholder="编码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input placeholder="名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary">查询</el-button>
          </el-form-item>
        </el-form>
        <!-- 新增按钮 -->
        <el-button
          type="primary"
          size="small"
          style="height: 32px"
          plain
          @click="add"
          >新增</el-button
        >
      </div>
    </div>

    <!-- table表格 -->
    <div class="table">
      <el-table :data="list" border style="width: 100%" height="500">
        <el-table-column prop="date" label="编码"></el-table-column>
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column prop="address" label="添加时间"></el-table-column>
        <el-table-column prop="address" label="更新时间"></el-table-column>
        <el-table-column prop="address" label="停用"></el-table-column>

        <el-table-column prop="address" label="操作" width="150">
          <template>
            <el-button size="mini" @click="edit">编辑</el-button>
            <el-popconfirm
              title="这是一段内容确定删除吗？"
              @confirm="confirmDel"
            >
              <el-button
                style="margin-left: 10px"
                size="mini"
                type="danger"
                slot="reference"
                >删除</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 新增和编辑的对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="showDialog"
      width="35%"
      :before-close="handleClose"
    >
      <el-form label-width="80px" style="width: 80%">
        <el-form-item label="编码">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="名称">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="停用">
          <el-checkbox></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      title: "新增",
      showDialog: false,
    };
  },

  methods: {
    // 封装一个处理弹窗关闭的方法：需要关闭的时候调用，清楚表单的数据，初始化表单
    handleClose() {
      this.showDialog = false;
    },
    cancel() {
      this.showDialog = false;
    },
    edit() {
      this.title = "编辑";
      this.showDialog = true;
    },
    // 确认删除的回调
    confirmDel() {
      this.$message.success("删除成功");
    },
    add() {
      this.title = "新增";
      this.showDialog = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.mapping-page {
  background-color: #fff;
  padding: 0 50px 50px 50px;

  .header {
    display: flex;
    text-align: center;
    justify-content: space-between;
    align-items: center;
    // padding: 0 50px;

    .title {
      font-size: 20px;
    }

    .right {
      display: flex;
      text-align: center;
      padding-top: 30px;
    }
  }

  .table {
  }

  .dialogBox {
    margin: 0 auto;
  }

  .drawerBox {
    // padding: 20px 40px;

    .rule {
    }
  }
}
</style>


